package cn.sc.allinpay.allfavour.business.set;

import android.os.Bundle;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import java.util.List;

import butterknife.BindView;
import cn.pai.common.adapter.BaseRecyAdapter;
import cn.sc.allinpay.allfavour.R;
import cn.sc.allinpay.allfavour.base.activity.BaseActivity;
import cn.sc.allinpay.allfavour.business.common.adapter.SetAdapter;
import cn.sc.allinpay.allfavour.business.common.data.SetData;
import cn.sc.allinpay.allfavour.business.setconfig.SetConfigActivity;
import cn.sc.allinpay.allfavour.business.setmanage.SetManageActivity;
import cn.sc.allinpay.allfavour.business.setpwd.SetPwdActivity;
import cn.sc.allinpay.allfavour.business.setremark.SetRemarkActivity;
import cn.sc.allinpay.allfavour.business.setting.SettingActivity;

/**
 * 设置
 */
public class SetActivity extends BaseActivity<SetContract.View, SetContract.Presenter> implements SetContract.View {

    @BindView(R.id.recycler)
    RecyclerView recycler;
    private SetAdapter adapter;

    @Override
    protected int layoutId() {
        return R.layout.activity_set;
    }

    @Override
    protected void layoutTitle(View top, AppCompatTextView left, AppCompatTextView title, AppCompatTextView right) {
        title.setText("管理");
    }

    @Override
    protected SetContract.Presenter bindPresenter() {
        return new SetPresenter();
    }

    @Override
    protected void layoutContent(Bundle savedInstanceState) {
        recycler.setLayoutManager(new GridLayoutManager(this, 3));// 列表布局
        adapter = new SetAdapter();
        recycler.setAdapter(adapter);
        adapter.setOnAdapterListener(new BaseRecyAdapter.OnAdapterListener<SetData>() {
            @Override
            public void onItemClick(View view, int position, SetData data) {
                String e = data.getNameEn();
                if ("settlement".equals(e)) {
                    presenter.settlement();
                } else if ("loginOut".equals(e)) {
                    presenter.loginOut();
                } else if ("setconfig".equals(e)) {
                    toActivity(SetConfigActivity.class, null);
                } else if ("cashierPwd".equals(e)) {
                    toActivity(SetPwdActivity.class, null);
                } else if ("checkRemark".equals(e)) {
                    toActivity(SetRemarkActivity.class, null);
                } else if ("managerPwd".equals(e)) {
                    toActivity(SetManageActivity.class, null);
                } else if ("serviceManage".equals(e)) {
                    toActivity(SettingActivity.class, null);
                }
            }
        });
    }

    @Override
    public void adapterChange(List<SetData> datas) {
        adapter.change(datas);
    }
}
